<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <link rel="stylesheet" href="__ADMIN__/wx/css/default.css">
        <script type="text/javascript" src="__ADMIN__/wx/js/jquery-1.6.4.min.js"></script>
        <script type="text/javascript" src="__ADMIN__/wx/js/jquery.form.js"></script>
		<style type="text/css">
			.demo{width:620px; margin:30px auto}
			.demo p{line-height:32px}
			.btnfile{position: relative;overflow: hidden;margin-right: 4px;display:inline-block;*display:inline;padding:4px 10px 4px;font-size:14px;line-height:18px;*line-height:20px;color:#fff;text-align:center;vertical-align:middle;cursor:pointer;background-color:#5bb75b;border:1px solid #cccccc;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}
			.btnfile input {position: absolute;top: 0; right: 0;margin: 0;border: solid transparent;opacity: 0;filter:alpha(opacity=0); cursor: pointer;}
			.progress { position:relative; margin-left:100px; margin-top:-24px; width:200px;padding: 1px; border-radius:3px; display:none}
			.bar {background-color: green; display:block; width:0%; height:20px; border-radius: 3px; }
			.percent { position:absolute; height:20px; display:inline-block; top:3px; left:2%; color:#fff }
			.files{height:22px; line-height:22px; margin:10px 0}
			.delimg{margin-left:20px; color:#090; cursor:pointer}
			.place{height:40px; background:url(__ADMIN__/images/righttop.gif) repeat-x;}
			.place span{line-height:40px; font-weight:bold;float:left; margin-left:12px;}
			.placeul li{float:left; line-height:40px; padding-left:7px; padding-right:12px; background:url(__ADMIN__/images/rlist.gif) no-repeat right;}
			.placeul li:last-child{background:none;}
		</style>
    </head>
    <body>
    	<div class="place">
		    <span>位置：</span>
		    <ul class="placeul">
		    	<li>首页</li>
		    	<li>添加优惠券</li>
		    </ul>
		</div>
        <div class="col_main">
        <form action="{:U('add')}" method="post" name="form_post" id="form_post">
			<table cellspacing="0" cellpadding="4" border="0" class="table-form">
				<tbody>
<!-- 				<tr> -->
<!-- 					<th width="200" class="first">商家：</th> -->
<!-- 					<td><input name="m_name" id="m_name" type="text"  size="40" class="textinput requireinput required" value="{$code.m_name}" readonly="readonly" /><input name="m_id" id="m_id" type="hidden" value="" />&nbsp;<a href="?g={$smarty.const.GROUP_NAME}&m=CouponCodeMall&a=select&is_iframe=1&keepThis=true&TB_iframe=true&height=440&width=750" title="选择商家" class="thickbox">选择商家</a></td> -->
<!-- 				</tr> -->
			    <tr>
					<th width="200" class="first">名称：</th>
					<td><input name="title" type="text"  size="40" class="textinput" value="{$code.title}" placeholder="新人优惠券" />(设定名称后优惠券标题将优先显示为该名称)</td>
				</tr>
			    <tr>
					<th width="200" class="first">类型：</th>
					<td>
					<select name="c_type" onchange="sel_c_type(this.value)">
					<foreach name="code_type_conf" item="item" key="key">
					<if condition="$code['c_type'] eq $key">
					<option value="{$key}" selected>
					<else /><option value="{$key}">
					</if>{$item}</option>
					</foreach>
					</select>
					<span id="c_type_elm_1">满<input name="money_max" id="money_max" type="text"  size="10" class="textinput requireinput number" value="{$code.money_max}" placeholder="100" />元&nbsp;减<input name="money_reduce" id="money_reduce" type="text"  size="10" class="textinput requireinput number" value="{$code.money_reduce}" placeholder="50" />元</span><span id="c_type_elm_2">金额：<input name="money_amount" id="money_amount" type="text"  size="10" class="textinput requireinput number" value="{$code.money_amount}" placeholder="100" />元</span></td>
				</tr>
			    <tr>
					<th width="200" class="first">有效期：</th>
					<td><select name="expiry_type" onchange="sel_expiry_type(this.value)">
					<foreach name="code_expiry_conf" item="item" key="key">
					<if condition="$code['expiry_type'] eq $key">
					<option value="{$key}" selected>
					<else /><option value="{$key}">
					</if>{$item}</option>
					</foreach>
					</select>
					<span id="expiry_type_elm_1"></span>
					</td>
				</tr>
			    <tr>
					<th width="200" class="first">使用说明：</th>
					<td><textarea name="directions" id="directions" cols="" rows="" class="textinput" style="height:150px; width:550px;">{$code.data.directions}</textarea></td>
				</tr>
			    <tr>
					<th width="200" class="first">温馨提示：</th>
					<td><textarea name="prompt" id="prompt" cols="" rows="" class="textinput" style="height:150px; width:550px;">{$code.data.prompt}</textarea></td>
				</tr>
				<tr class="act">
					<th class="first">&nbsp;</th>
					<td>
						<input type="submit" value="提交" class="submit_btn">
						<input type="reset" value="重置" class="reset_btn">
					</td>
				</tr>
			</tbody>
			</table>
		</form>
        <script type="text/javascript">
			var c_type = 1;
			var expiry_type = 1;
			var tb_pathToImage = "__PUBLIC__/Js/thickbox/loadingAnimation.gif";
			var upscript_url = '__APP__?g=Public&m=Public&a=upload4xheditor&immediate=1';
			var editor = null;
			function sel_c_type(c_type)
			{
				$('#c_type_elm_1,#c_type_elm_2').hide();
				$('#c_type_elm_'+c_type).show();
				if(c_type == 1){
					$('#money_max,#money_reduce').addClass('required');
					$('#money_amount').removeClass('required');
				}else{
					$('#money_max,#money_reduce').removeClass('required');
					$('#money_amount').addClass('required');
				}
			}
			function sel_expiry_type(expiry_type)
			{
				if(expiry_type != 1){
					var html = '';
					if (expiry_type == 2) {
						html = '有效期至<input type="Text" name="expiry" class="Wdate textinput requireinput"  id="expiry" style="cursor: hand; width:160px;" value="" placeholder="2015-09-21">';
					} else {
						html = '<input type="Text" name="expiry" class="Wdate textinput requireinput"  id="expiry" style="cursor: hand; width:160px;" value="" placeholder="60">天后过期';
					}
					$('#expiry_type_elm_1').empty().append(html);
					$('#expiry_type_elm_1').show();
					
					if (expiry_type == 2) {
						$('#expiry_type_elm_1').find('input').focus(function () {
							WdatePicker({skin:'ext',dateFmt:'yyyy-MM-dd',isShowToday:false,lang:'zh_cn',readOnly:true});
						});
					}
					$('#expiry').addClass('required');
				}else{
					$('#expiry_type_elm_1').hide();
					$('#expiry').removeClass('required');
				}
			}
			
			function pick_mall_handler(mall)
			{
				if(mall !== null){
					$('#m_id').val(mall.m_id);
					$('#m_name').val(mall.m_name);
				}
				tb_remove();
			}
			$(document).ready(function() {
				
				$(".submit_btn").click(function () {
					var title = $('[name="title"]').val();
					if ($.trim(title) == '') {
						alert('优惠券名不能为空');
						return false;
					}
					
					var select = $('[name="c_type"]').val();
					if (select == 1) {
						var money_max = $("#money_max").val();
						var money_reduce = $("#money_reduce").val();
						
						var reg=/^\d+$/;
						if (!reg.test(money_max) || money_max == 0) {
							alert('请输入金额');
							return false;
						}
						
						if (!reg.test(money_reduce) || money_reduce == 0) {
							alert('请输入减金额');
							return false;
						}
						
						if (money_max < money_reduce) {
							alert('满减券的满的金额不能小于减金额');
							return false;
						}
					} else {
						var money_amount = $("#money_amount").val();
						var reg=/^\d+$/;
						if (!reg.test(money_amount) || money_amount == 0) {
							alert('请输入代金券金额');
							return false;
						}
					}
					
					var expiry_type = $('[name="expiry_type"]').val(),
						expiry = $("#expiry").val();
					if (expiry_type == 2){
						if ($.trim(expiry) == '') {
							alert('请输有效日期');
							return false;
						}
					} else if (expiry_type == 3){
						if ($.trim(expiry) == '') {
							alert('请输有效天数');
							return false;
						}
					}
					
					return true;
				});
				
				sel_c_type(c_type);
				sel_expiry_type(expiry_type);
// 				tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
// 				imgLoader = new Image();// preload image
// 				imgLoader.src = tb_pathToImage;
// 				var options = {elm:'#directions,#prompt',tools:'simple',upscript_url:upscript_url};
// 				editor = editorInit(options);
			});
		</script>
    </body>
</html>